"""
 Coatl 2008 GPLv3
 Colectivo MonoNeurona.org
"""
from django.shortcuts import render_to_response
from django.db import models
from django.core.mail import send_mail
from django.http import Http404
from models import Poll
from datetime import datetime
import os, unittest


def latest_polls(request):
    polls_list = Poll.objects.order_by('date')[:10]
    return render_to_response('polls/display.html', {'polls_list':polls_list})

def view(request, offset):
    #raise Exception(repr(offset))
  
    poll_id = int(offset)
    
    try:
       #poll = Poll.objects.filter(published=True).order_by("-id")[:1]
       poll = Poll.objects.get(pk=poll_id)
       mydict = {'poll':poll}
       #exit(raise Exception(repr(post)))
       #if  poll.published == True:
       #  mydict['f']  = 'forma'
       #else:
       #  mydict['f']  = 'no hay forma'
    except Poll.DoesNotExist:
        raise Http404
    return render_to_response('polls/view.html', mydict)

def display(request):
    polls = Poll.objects.filter(published=True).order_by("id")[:10]
    #__newMail()
    return render_to_response('news/display.html', {'polls':polls})
